// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css';
import axios from './untils/http'
import md5 from 'js-md5';
// import './assets/global.css'
import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'
import infiniteScroll from 'vue-infinite-scroll';

Vue.config.productionTip = false



Vue.prototype.$axios = axios
Vue.prototype.$md5 = md5



Vue.use(ElementUI)
Vue.use(mavonEditor)
Vue.use(infiniteScroll)

//路由拦截，要是未登录.不允许进入这些页面
const blackList1 = ['/user/profile','/user/chatroom','/user/blog','/user/follow','/user/fans','/blog/fwb','/blog/markdown']

//路由拦截，要是登录了，不允许进入这些页面
const blackList2 = ['/user/login', '/user/register']

router.beforeEach((to, from, next) => {

    //如果已经登录并且路由不是到登录，注册页面
    if(document.cookie.length>0){
        if(blackList2.indexOf(to.path) !== -1){
          next('/')
        }else{
          next()
        }
    }else if(document.cookie.length==0){
      if(blackList1.indexOf(to.path) == -1){
        next()
      }else{
        next('/user/login')
      }
    }

})


/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
